package com.mlog.njyjy.ndop.monitor.redis;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import com.mlog.njyjy.ndop.monitor.pojo.MessageDO;

import cn.hutool.json.JSONUtil;

import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;


@Slf4j
@Component
public abstract class RedisClient {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Value("${redis.out.time}")
    private String time;

    public Set<String> get_set_msg(String key) {
        return redisTemplate.opsForSet().members(key);
    }

    public boolean exists_set_msg(String key, String val) {
        return redisTemplate.opsForSet().isMember(key, val);
    }

    public String get_str_msg(String key) {
        return redisTemplate.opsForValue().get(key);
    }

    public List<String> get_list_msg(String key) {
        return redisTemplate.opsForList().range(key, 0, -1);
    }
    
    public MessageDO getMsg(String msgKey) {
    	String body = get_str_msg(msgKey);
    	MessageDO msg = JSONUtil.toBean(body, MessageDO.class);
    	msg.setBody(body);
    	return msg;
    }
}
